package com;


import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.util.ArrayList;
import java.util.List;

public class RemoveNum {
	private static List<String> javalist=new ArrayList<String>();
	
	public static  void main(String[] args) {
//		String url="D:\\unicomfby";
		
		String url=args[0];
		File filelist = new File(url);
		System.out.println("start");
		dg(filelist);
		for(int i=0;i<javalist.size();i++) {
//			File file = new File(javalist.get(i));
			readline(javalist.get(i));
		}
		
		System.out.println("end");
	}
	
	public static void readline(String file) {
			// 在E盘下新建一个文本文件
			File file1 = new File(file); // 创建File类对象
			FileInputStream fis = null; // 创建FileInputStream类对象读取File
			InputStreamReader isr = null; // 创建InputStreamReader对象接收文件流
			BufferedReader br = null; // 创建reader缓冲区将文件流装进去
			File newfile = new File(file.replace(".java", "1.java"));
			try {
				fis = new FileInputStream(file1);
				isr = new InputStreamReader(fis);
				br = new BufferedReader(isr);
				String lineTxt = null;
				
				
				if(!newfile.exists()){
					newfile.createNewFile();
	   	        }
				//文件输出流
				FileOutputStream fos = new FileOutputStream(newfile);
				BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(fos));
				
				// 从缓冲区中逐行读取代码，调用readLine()方法
				while ((lineTxt = br.readLine()) != null) {
					
					if(lineTxt.indexOf("/*")>-1&&lineTxt.indexOf("*/")>-1) {						
						lineTxt=lineTxt.substring(lineTxt.indexOf("*/")+3);
					}
					System.out.println(lineTxt); // 逐行输出文件内容
					bw.write(lineTxt);
					bw.newLine();
				}
				bw.close();
				
				
			} catch (FileNotFoundException e) {
				e.printStackTrace();
			} catch (IOException e) {
				e.printStackTrace();
			} finally {
				// 文件执行完毕别忘了关闭数据流
				if (br != null) {
					try {
						br.close();
					} catch (IOException e) {
						e.printStackTrace();
					}
				}
				if (isr != null) {
					try {
						isr.close();
					} catch (IOException e) {
						e.printStackTrace();
					}
				}
				if (fis != null) {
					try {
						fis.close();
					} catch (IOException e) {
						e.printStackTrace();
					}
				}
			}
			file1.delete();
			//对文件重命名
			File fileOK = new File(file); 
			newfile.renameTo(fileOK);
		}
	 
	
	public static void dg(File filelist) {
		File[] file=filelist.listFiles();
		 for(int i=0;i<file.length;i++) {
			 if(file[i].isFile()) {				 
				 if(file[i].getName().indexOf(".java")>0) {
					 System.out.println(file[i].getAbsolutePath());
					 javalist.add(file[i].getAbsolutePath());
				 }
			 }else {
				 dg(file[i]);
			 }
		 }
	}
}
